﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Eacademy.Library.Helpers
{
    public class DateHelper
    {
        public DateHelper()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static string ConvertToMySQLDate(DateTime date)
        {
            return (date.ToString("yyyy-MM-dd HH:mm:ss"));
        }

        public static string GetMonthName(int month)
        {
            DateTime date = new DateTime(1900, month, 1);
            return date.ToString("MMMM");
        }

        public static string FormatLastUpdatedDate(DateTime lastUpdateDate, DateTime currentDate)
        {
            TimeSpan delta = currentDate.Subtract(lastUpdateDate);
            if (delta.Days > 7)
                return lastUpdateDate.ToShortDateString();
            else if (delta.Days > 1)
                return string.Format("{0} days ago", delta.Days);
            else if (delta.Days == 1)
                return string.Format("Yesterday", delta.Days);
            else if (delta.Hours > 1)
                return string.Format("{0} hours ago", delta.Hours);
            else if (delta.Hours == 1)
                return string.Format("1 hour ago", delta.Hours);
            else if (delta.Minutes > 1)
                return string.Format("{0} minutes ago", delta.Minutes);
            else if (delta.Minutes == 1)
                return string.Format("1 minute ago", delta.Minutes);
            else
                return "A few seconds ago";
        }
    }
}